package org.example.controller;

import org.springframework.web.bind.annotation.*;

@RestController
public class ArithmeticController {

    @RequestMapping("/jsq")
    public double calculate(@RequestParam("x") double num1, @RequestParam("y") double num2, @RequestParam("method") String operator) {
        double result = 0;

        switch (operator) {
            case "add":
                result = num1 + num2;
                break;
            case "sub":
                result = num1 - num2;
                break;
            case "mul":
                result = num1 * num2;
                break;
            case "div":
                if (num2 != 0) {
                    result = num1 / num2;
                } else {
                    throw new IllegalArgumentException("Cannot divide by zero");
                }
                break;
            default:
                throw new IllegalArgumentException("Invalid operator");
        }

        return result;
    }
}
